<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"><style>
    *{
        margin:0;
        padding:0;
    }
    body {
        margin: 0;
        padding: 0;
        width: 1280px;
        height: 720px;
        font-family: "微软雅黑", "黑体";
        color: #cfcff5;
    }
    #loading{
        width:128px;
        height:128px;
        position:absolute;
        left:576px;
        top:270px;
        z-index:100;
    }
    #loading2{
        width:128px;
        height:50px;
        position:absolute;
        left:576px;
        top:410px;
        z-index:100;
    }
    #resume{
        width:80px;
        height:80px;
        background:url("../images/player/resume.png") no-repeat center center;
        background-size:80px 80px;
        position:absolute;
        left:600px;
        top:320px;
        z-index: 10;
        display:none;
    }
    #vol{
        width:120px;
        padding-left:70px;
        height:52px;
        line-height:52px;
        font-size:34px;
        color:#fff;
        background:url("../images/player/vol.png") no-repeat left center;
        position:absolute;
        left:1060px;
        top:80px;
        z-index:10;
        display:none;
    }
</style>
    <script type="text/javascript" src="../js/yajax.js"></script>
    <script type="text/javascript" src="../js/use.js"></script>
</head>
<body onload="vedioInit();">

    <div id="videoplay" style="top:200px;left:200px;height: 400px;width: 900px;"></div>

    <!--加载提示-->
    <img src="../images/player/loading.gif" id="loading">
    <img src="../images/player/loading2.gif" id="loading2">

    <!--暂停播放-->
    <div id="resume"></div>

    <!--音量-->
    <p id="vol"></p>

    <script type="text/javascript">
        var mediaSource = decodeURI(tools.GetQueryString("video_url"));//获取视频播放链接地址
        var $mp;
        var nativePlayerInstanceID;
        var isNewVersion = false;
        var vol;//音量
        var timer;//定时器，保存音量提示
        var status=0;//播放状态，0为停止播放，1为正在播放，2为继续播放

        document.onsystemevent = globalEventListener; //捕获系统事件消息
        function globalEventListener(event){
            var keyCode = event.which;
            var code = "";
    //		var messageId = event.modifiers;

            switch(keyCode){
    //		这里统一处理遥控器和系统事件消息，每个消息对应一个keyCode.
                case 13003://开始播放成功！
                    $mp.enableTrickMode(true);
                    status=1;
                    document.getElementById('loading').style.display='none';
                    document.getElementById('loading2').style.display='none';
                    break;
                case 13004://开始播放失败！
                    break;
                case 13005://步长设置成功!
                    break;
                case 13006://步长设置失败!
                    break;
                case 13007://设置播放时间点成功!
                    break;
                case 13008://设置播放时间点失败!
                    break;
                case 13009://暂停播放成功!
                    document.getElementById('resume').style.display='block';
                    status=2;
                    break;
                case 13010://暂停播放失败!
                    break;
                case 13011://恢复播放成功!
                    document.getElementById('resume').style.display='none';
                    status=1;
                    break;
                case 13012://恢复播放失败!
                    break;
                case 13013://停止播放成功!
                    status=0;
                    break;
                case 13014://停止播放失败!
                    break;
                case 13015://当前媒体已经播放完毕
                    status=0;
                    vedioDestroy();
                    history.go(-1);
                    break;
            }
        }

        function vedioInit(){
            isNewVersion = typeof MediaPlayer != "undefined";
            if(isNewVersion){
                vedioInitByNewVersion();
            }

            var videoplay = document.getElementById("videoplay");
            if(videoplay != null){
                var videowindow = document.createElement("object");
                videowindow.setAttribute("type","application/NDS-JS-EXT-videoWindow");
                videowindow.setAttribute("width","1280");
                videowindow.setAttribute("height","720");
                videowindow.setAttribute("id","videoPluginId");
                //videowindow.id = "videoPluginId";
                videoplay.appendChild(videowindow);
            }
            CreateVideoWindowObject();
        }


        function vedioInitByNewVersion(){
            $mp = new MediaPlayer();
            if(GlobalVarManager.getItemValue("PLAYER_INSTANCE_ID")==null){
                nativePlayerInstanceID = $mp.getPlayerInstanceID();
                GlobalVarManager.setItemValue("PLAYER_INSTANCE_ID",nativePlayerInstanceID);
            }else{
                nativePlayerInstanceID = GlobalVarManager.getItemValue("PLAYER_INSTANCE_ID");
            }
            $mp.enableTrickMode(true);
            $mp.bindPlayerInstance(nativePlayerInstanceID);
            $mp.setMediaSource(mediaSource);
            $mp.play();
            $mp.setVideoDisplayMode(1);
            $mp.refresh();
        }

        function vedioDestroy(){
            if(isNewVersion){
                vedioDestroyByNewVersion();
            }else{
                DestroyVideoWindowObject();
            }
        }

        function vedioDestroyByNewVersion(){
            $mp.stop();
            $mp.clearVideoOutput();
            $mp.unbindPlayerInstance(nativePlayerInstanceID);
        }

        function CreateVideoWindowObject(){
            var videoPluginObj = document.getElementById("videoPluginId");
            if(videoPluginObj != null){
                try {
                    ServiceSelection.tune(mediaSource,2);
                    videoPluginObj.setOutputVideoWindow(0,0,1280,720);
                    videoPluginObj.enableVidoWindow(true);
                    SysUtil.setMute(false,true);
                    /* if(SysUtil){
                     SysUtil.setMute(true,true);
                     document.getElementById("msgl").innerHTL = "have";
                     document.getElementById("message1").style.display = "block";
                     }else{
                     document.getElementById("msgl").innerHTML = "none";
                     document.getElementById("message1").style.display = "block";
                     } */
                } catch (e) {
                    // TODO: handle exception
                }
            }
        }

        //调高声音
        function volUp() {
            vol = $mp.getVolume();
            if (vol < 96) {
                vol = vol + 5;
                $mp.setVolume(vol);
            }else{
                vol =100;
                $mp.setVolume(vol);
            }
            clearTimeout(timer);
            document.getElementById('vol').innerHTML=vol;
            document.getElementById('vol').style.display='block';
            timer=setTimeout(function(){document.getElementById('vol').style.display='none';},3000)
        }

        //降低声音
        function volDown() {
            vol = $mp.getVolume();
            if (vol > 4) {
                vol = vol - 5;
                $mp.setVolume(vol);
            }else{
                vol =0;
                $mp.setVolume(vol);
            }
            clearTimeout(timer);
            document.getElementById('vol').innerHTML=vol;
            document.getElementById('vol').style.display='block';
            timer=setTimeout(function(){document.getElementById('vol').style.display='none';},3000)
        }

        function DestroyVideoWindowObject(){
            var vidwoPluginObj = document.getElementById("videoPluginId");
            if(videoPluginObj !=null){
                try {
                    videoPluginObj.enableVideoWindow(false);
                    if(SysUtil){
                        SysUtil.setMute(true,true);
                    }
                } catch (e) {
                    // TODO: handle exception
                }
            }
        }

        function getDivContentDecide(id) {
            return document.getElementById(id).innerHTML.replace(/(^\s*)|(\s*$)/g,
                    "")
        }

        var clickFunction = function(keyEvent) {
            keyEvent = keyEvent ? keyEvent : window.event;
            keyEvent.which = keyEvent.which ? keyEvent.which : keyEvent.keyCode;
            keycontrol(keyEvent);
        };
        //window.document.onkeypress = clickFunction;
        window.document.onkeydown = clickFunction;

        var keyopt = {
            options : {
                focusElm : "now"
            },
            moveBtn : function(toDirection) {
                //移动之前的id
                var oldBtnId = this.options.focusElm;
                //将移动之前的元素json信息解析成json对象
                var old_obj_json = eval(oldBtnId + "_json");
                //获取移动目的地的id信息
                var goElm = old_obj_json[toDirection];
                if (goElm == "") {
                    geElm = oldBtnId;
                }
                var new_btn = document.getElementById(goElm);
                if (new_btn) {
                    var onfocusFuc = eval(goElm + "_onfocus");
                    var onblurFuc = eval(oldBtnId + "_onblur");
                    onblurFuc(toDirection, oldBtnId);
                    this.options.focusElm = goElm;
                    onfocusFuc(toDirection, goElm);
                }
            },
            marksure : function() {
                var onsubmitFuc = eval(this.options.focusElm + "_onsubmit");
                onsubmitFuc();
            },
            input : function(code) {
                var onkeypressFuc = eval(this.options.focusElm + "_onkeypress");
                onkeypressFuc(code);
            },
            moveToElm : function(id) {
                var to_elm = document.getElementById(id);
                if (to_elm) {
                    var onfocusFuc = eval(id + "_onfocus");
                    var onblurFuc = eval(this.options.focusElm + "_onblur");
                    onfocusFuc();
                    this.options.focusElm = id;
                    onblurFuc();
                }
            },
            addClass : function(id, className) {
                document.getElementById(id).className += " " + className;
            },
            removeClass : function(id, className) {
                document.getElementById(id).className = document.getElementById(id).className
                        .replace(className, '');
            },
            replaceClass : function(id, searchClass, replaceClass) {
                var className = document.getElementById(id).className;
                document.getElementById(id).className = className.replace(
                        searchClass, replaceClass)
            }
        };

        function keycontrol(obj) {
            if (obj.which == 0x0026) {
                /*  上  */
            } else if (obj.which== 0x0028) {
                /*  下  */
            } else if (obj.which== 0x0025) {
                /*  左  */
            } else if (obj.which== 0x0027) {
                /*  右  */
            }else if(obj.which == 0x0013) {
                //暂停
                $mp.pause();
            }else if(obj.which == 1045||obj.which == 0x019F) {
                //播放
                if(status=='2'){
                    $mp.resume();
                }else if(status=='0'){
                    $mp.play();
                }
                $mp.resume();
            } else if (obj.which== 0x000D) {
                /*  确定  */
                if(status=='1') {
                    $mp.pause();
                }else if(status=='2'){
                    $mp.resume();
                }else if(status=='0'){
                    $mp.play();
                }
            } else if ((obj.which<=0x0038&&obj >= 0x0030) || obj.which== 0x118 || obj.which== 280) {
            } else if (obj.which== 113 || obj.which == 0x0008) {//返回
    //				obj.stopPropagation();
    //				obj.preventDefault();
                vedioDestroy();
                history.go(-1);
            }else if(obj.which== 0x0447) {//音量＋键
                volUp();
            }else if(obj.which== 0x0448) {//音量－键
                volDown();
            }
        }
    </script>
</body>
</html>